/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import com.openbrew.openbrewrf.views.POSSupplyView;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author dchapman
 */
@Entity
@Table(name = "posLineItems")
@XmlRootElement
public class POSLineItems implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "lineItemID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "lineItemTimestamp")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lineItemTimestamp;
    @Basic(optional = false)
    @NotNull
    @Column(name = "quantity")
    private int qty;
    @Basic(optional = false)
    @NotNull
    @Column(name = "priceOverRide")
    private float priceOverRide;
    @JoinColumn(name = "product", referencedColumnName = "servingTypeID", nullable=true)
    @ManyToOne(optional=true)
    private POSProductServingType product;
    @JoinColumn(name = "supply", referencedColumnName = "SupID", nullable=true)
    @ManyToOne(optional=true)
    private POSSupplyView supply;
    @JoinColumn(name = "discount", referencedColumnName = "posDiscountID", nullable=true)
    @ManyToOne(optional=true)
    private POSDiscount discount;
    @OneToOne
    @JoinColumn(name = "tasterTray", referencedColumnName = "trayID", nullable=true)
    private POSTasterTray tasterTray;

    public POSLineItems() {
    }

    public POSLineItems(Integer id) {
        this.id = id;
    }

    public POSLineItems(Integer id, Date lineItemTimestamp, int qty, float priceOverRide) {
        this.id = id;
        this.lineItemTimestamp = lineItemTimestamp;
        this.qty = qty;
        this.priceOverRide = priceOverRide;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getLineItemTimestamp() {
        return lineItemTimestamp;
    }

    public void setLineItemTimestamp(Date lineItemTimestamp) {
        this.lineItemTimestamp = lineItemTimestamp;
    }

    public int getQty() {
        return qty;
    }

    public void setQty(int qty) {
        this.qty = qty;
    }

    public float getPriceOverRide() {
        return priceOverRide;
    }

    public void setPriceOverRide(float priceOverRide) {
        this.priceOverRide = priceOverRide;
    }

    public POSProductServingType getProduct() {
        return product;
    }

    public void setProduct(POSProductServingType product) {
        if(product != null && product.getId() != null){
            this.product = product;
        }
    }

    public POSSupplyView getSupply() {
        return supply;
    }

    public void setSupply(POSSupplyView supply) {
        if(supply != null && supply.getSupID() != null){
            this.supply = supply;
        }
    }

    public POSDiscount getDiscount() {
        return discount;
    }

    public void setDiscount(POSDiscount discount) {
        if(discount != null && discount.getId() != null){
            this.discount = discount;
        }
    }

    public POSTasterTray getTasterTray() {
        return tasterTray;
    }

    public void setTasterTray(POSTasterTray tasterTray) {
        if(tasterTray != null && tasterTray.getId() != null){
            this.tasterTray = tasterTray;
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof POSLineItems)) {
            return false;
        }
        POSLineItems other = (POSLineItems) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.poslineitems[ id=" + id + " ]";
    }
}
